﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLySim.BLO;

namespace QuanLySim
{
    public partial class frmDangNhap : Form
    {
        private clsDangNhapBLO m_DangNhapBlo;
        private bool m_DangNhap;
        private string m_strTenDangNhap;
        public frmDangNhap()
        {
            InitializeComponent();
            m_DangNhapBlo = new clsDangNhapBLO();
            m_DangNhap = false;
            m_strTenDangNhap = "";
        }

        public bool DANGNHAP
        {
            get { return m_DangNhap; }
            set { m_DangNhap = value; }
        }

        public string TENDANGNHAP
        {
            get { return m_strTenDangNhap; }
            set { m_strTenDangNhap = value; }
        }

        private bool DangNhap(string strTen, string strMatKhau)
        {
            DataTable Table = new DataTable();
            Table = m_DangNhapBlo.DangNhap();
            if (Table != null)
            {
                foreach (DataRow row in Table.Rows)
                {
                    if (strTen == row[0].ToString() && strMatKhau == row[1].ToString())
                    {
                        return true;                    
                    }
                }
            }
            else
            {
                MessageBox.Show("Lỗi: " + m_DangNhapBlo.ERORR, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return false;
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (DangNhap(this.txtTenDangNhap.Text, this.txtMatKhau.Text))
            {
                m_DangNhap = true;
                m_strTenDangNhap = this.txtTenDangNhap.Text;
                this.Close();
            }
            else
            {
                MessageBox.Show("Đăng nhập không đúng !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {

        }
    }
}